package myzd.api.controllers;

import io.swagger.annotations.*;
import libedge.annotations.Authentication;
import libedge.domain.exceptions.GenericException;
import libedge.domain.request.ResultWrapper;
import lombok.extern.slf4j.Slf4j;
import myzd.client.domain.UploadToken;
import myzd.services.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author zks
 * @since 2017/10/18 18:31
 */
@RestController
@Slf4j
@Api(description = "通用模块管理")
public class CommonController {

  @Autowired
  private ClientService clientService;

  @GetMapping("api/v1/Common/uploadToken")
  @ApiOperation(value = "获取上传token", produces = "application/json")
  @Authentication
  @ApiImplicitParams({
    @ApiImplicitParam(name = "Authorization", value = "Session Id", required = true, dataType = "string", paramType = "header")
  })
  public ResultWrapper<UploadToken> getFileToken(
    @ApiParam(value = "图片类型(病例图片：1，手术小结图片 ：2，医生胸牌照片：6，医生肖像)", required = true) @RequestParam(value = "type") Integer type,
    @ApiParam(value = "图片原文件名(加扩展名)", required = true) @RequestParam(value = "fileName", required = true) String fileName,
    @ApiParam(value = "文件大小", required = true) @RequestParam(value = "fileSize", required = true) Integer fileSize,
    @ApiParam(value = "扩展名", required = true) @RequestParam(value = "MIME", required = true) String mime
  ) throws GenericException, IOException {
    return new ResultWrapper<>(clientService.getFileToken(type, fileName, fileSize, mime));
  }


}
